import 'package:flutter/material.dart';

class NavItem {
  final IconData icon;
  final String title;

  NavItem({required this.icon, required this.title});
}

final List<NavItem> navItems = [
  NavItem(icon: Icons.wifi, title: "WiFi电话卡"),
  NavItem(icon: Icons.shield, title: "保险·签证"),
  NavItem(icon: Icons.currency_exchange, title: "外币兑换"),
  NavItem(icon: Icons.shopping_bag, title: "购物"),
  NavItem(icon: Icons.accessibility, title: "当地向导"),
  NavItem(icon: Icons.backpack, title: "自由行"),
  NavItem(icon: Icons.landscape, title: "境外玩乐"),
  NavItem(icon: Icons.card_giftcard, title: "礼品卡"),
  NavItem(icon: Icons.credit_card, title: "信用卡"),
  NavItem(icon: Icons.more_horiz, title: "更多"),
];

class SubNavGrid extends StatelessWidget {
  const SubNavGrid({super.key});

  @override
  Widget build(BuildContext context) {
    return GridView.count(
      physics: const NeverScrollableScrollPhysics(), // 禁止滚动（若父组件可滚动）
      shrinkWrap: true, // 自适应高度
      crossAxisCount: 5, // 每行5列
      childAspectRatio: 1, // 宽高比（控制图标和文字的整体大小）
      padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
      children: navItems.map((item) {
        return GestureDetector(
          onTap: _ontap(),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Icon(
                item.icon,
                color: Colors.orange, // 图标颜色
                size: 24, // 图标大小
              ),
              const SizedBox(height: 4), // 图标和文字的间距
              Text(
                item.title,
                style: const TextStyle(fontSize: 12, color: Colors.black87),
              ),
            ],
          ),
        );
      }).toList(),
    );
  }

  _ontap() {
    //点击后的反应
  }
}
